package com.azzcs.mvc.servlet;

import java.lang.reflect.Method;
import java.lang.reflect.Parameter;

/**
 * @Author: wzg
 * @Date: 2020/12/28 下午4:27
 */
public class HandlerMethod {
    private final Object bean;
    private final Class<?> beanType;
    private final Method method;
    private final String[] parameters;

    public HandlerMethod(Object bean, Method method) {
        this.bean = bean;
        this.beanType = bean.getClass();
        this.method = method;
        this.parameters = initParameters(beanType,method);
    }

    private String[] initParameters(Class<?> beanType, Method method) {
        Parameter[] parameters = method.getParameters();
        String[] result = new String[parameters.length];
        for (int i = 0; i < parameters.length; i++) {
            result[i] = parameters[i].getName();
        }
        return result;
    }

    public Class<?> getBeanType() {
        return beanType;
    }

    public Method getMethod() {
        return method;
    }

    public Object getBean() {
        return bean;
    }
}
